package com.hello.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hello.common.log.annotation.Log;
import com.hello.common.log.enums.BusinessType;
import com.hello.common.security.annotation.RequiresPermissions;
import com.hello.system.domain.ReportTemplate;
import com.hello.system.service.IReportTemplateService;
import com.hello.common.core.web.controller.BaseController;
import com.hello.common.core.web.domain.AjaxResult;
import com.hello.common.core.utils.poi.ExcelUtil;
import com.hello.common.core.web.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 报模板配置Controller
 * 
 * @author hello
 * @date 2025-09-09
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/reportTemplate")
public class ReportTemplateController extends BaseController
{
    private final IReportTemplateService reportTemplateService;

    /**
     * 查询报模板配置列表
     */
    @RequiresPermissions("system:reportTemplate:list")
    @GetMapping("/list")
    public TableDataInfo list(ReportTemplate reportTemplate)
    {
        startPage();
        List<ReportTemplate> list = reportTemplateService.selectReportTemplateList(reportTemplate);
        return getDataTable(list);
    }

    /**
     * 导出报模板配置列表
     */
    @RequiresPermissions("system:reportTemplate:export")
    @Log(title = "报模板配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReportTemplate reportTemplate)
    {
        List<ReportTemplate> list = reportTemplateService.selectReportTemplateList(reportTemplate);
        ExcelUtil<ReportTemplate> util = new ExcelUtil<ReportTemplate>(ReportTemplate.class);
        util.exportExcel(response, list, "报模板配置数据");
    }

    /**
     * 获取报模板配置详细信息
     */
    @RequiresPermissions("system:reportTemplate:query")
    @GetMapping(value = "/{templateId}")
    public AjaxResult getInfo(@PathVariable("templateId") Long templateId)
    {
        return success(reportTemplateService.selectReportTemplateByTemplateId(templateId));
    }

    /**
     * 新增报模板配置
     */
    @RequiresPermissions("system:reportTemplate:add")
    @Log(title = "报模板配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReportTemplate reportTemplate)
    {
        return toAjax(reportTemplateService.insertReportTemplate(reportTemplate));
    }

    /**
     * 修改报模板配置
     */
    @RequiresPermissions("system:reportTemplate:edit")
    @Log(title = "报模板配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReportTemplate reportTemplate)
    {
        return toAjax(reportTemplateService.updateReportTemplate(reportTemplate));
    }

    /**
     * 删除报模板配置
     */
    @RequiresPermissions("system:reportTemplate:remove")
    @Log(title = "报模板配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templateIds}")
    public AjaxResult remove(@PathVariable Long[] templateIds)
    {
        return toAjax(reportTemplateService.deleteReportTemplateByTemplateIds(templateIds));
    }
}
